**************************************************************
* GSS
**************************************************************

* Note: save all waves in one folder first

cd "SET_YOUR_PATH\GSS"

*2006-2010
use ".\2006\GSS_panel06w123_R6a - Stata.dta", clear

keep  age_1 age_2 age_3 confed_1 confed_2 confed_3 coninc_1 coninc_2 coninc_3 conjudge_1 conjudge_2 conjudge_3 conlegis_1 conlegis_2 conlegis_3 /// 
	degree_1 degree_2 degree_3 educ_1 educ_2 educ_3 hompop_1 hompop_2 hompop_3 /// 
	id_1 id_2 id_3 income06_1 income06_2 income06_3  /// 
	intintl_1 intintl_2 intintl_3 intmil_1 intmil_2 intmil_3 /// 
	madeg_1 madeg_2 madeg_3 maeduc_1 maeduc_2 maeduc_3 masei_1 masei_2 masei_3 /// 
	padeg_1 padeg_2 padeg_3 paeduc_1 paeduc_2 paeduc_3 partyid_1 partyid_2 partyid_3 pasei_1 pasei_2 pasei_3 /// 
	polbstgw_1 polbstgw_2 polbstgw_3  polviews_1 polviews_2 polviews_3  /// 
	polint1_1 polint1_2 polint1_3 race_1 race_2 race_3 /// 
	satfin_1 satfin_2 satfin_3 sei_1 sei_2 sei_3 sex_1 sex_2 sex_3 /// 
	wrkstat_1 wrkstat_2 wrkstat_3  born_1

clonevar sex = sex_1	
clonevar race = race_1
recode race (2=1 "black")(1 3=0 "other")(else=.), gen(black)
recode race (3=1 "other race")(1 2=0 "white or black")(else=.), gen(race_other)

recode born_1 (1=0 "no migrant")(2=1 "migrant")(else=.), gen(migrant)

gen birthyear = 2006 - age_1
drop age_*

gen edu = degree_3
replace edu = degree_2 if edu==.a | edu==.i
replace edu = degree_1 if edu==.a | edu==.i
recode edu (2/4=1 "college")(0 1=0 "hs or lower")(else=.), gen(college)
	
rename *_1 *_2006
rename *_2 *_2008
rename *_3 *_2010

rename income06_2006 income_2006
rename income06_2008 income_2008
rename income06_2010 income_2010

gen id = _n

save ".\2006\GSS_panel_2006_short.dta", replace

*2008-2012
use ".\2008\GSS_panel08w123_R6 - stata13.dta", clear

keep  age_1 age_2 age_3 confed_1 confed_2 confed_3 coninc_1 coninc_2 coninc_3 conjudge_1 conjudge_2 conjudge_3 conlegis_1 conlegis_2 conlegis_3 /// 
	degree_1 degree_2 degree_3 educ_1 educ_2 educ_3 hompop_1 hompop_2 hompop_3 id_1 id_2 id_3 /// 
	income06_1 income06_2 income06_3 INTINTL_1 INTINTL_2 INTINTL_3 INTMIL_1 INTMIL_2 INTMIL_3 /// 
	madeg_1 madeg_2 madeg_3 maeduc_1 maeduc_2 maeduc_3 masei_1 masei_2 masei_3 /// 
	padeg_1 padeg_2 padeg_3 paeduc_1 paeduc_2 paeduc_3 pasei_1 pasei_2 pasei_3 partyid_1 partyid_2 partyid_3  /// 
	polviews_1 polviews_2 polviews_3 race_1 race_2 race_3 satfin_1 satfin_2 satfin_3 /// 
	sei_1 sei_2 sei_3 sex_1 sex_2 sex_3 wrkstat_1 wrkstat_2 wrkstat_3 born_1

clonevar sex = sex_1	
clonevar race = race_1
recode race (2=1 "black")(1 3=0 "other")(else=.), gen(black)
recode race (3=1 "other race")(1 2=0 "white or black")(else=.), gen(race_other)

recode born_1 (1=0 "no migrant")(2=1 "migrant")(else=.), gen(migrant)

gen birthyear = 2008 - age_1
drop age_*
	
gen edu = degree_3
replace edu = degree_2 if edu==.a | edu==.i
replace edu = degree_1 if edu==.a | edu==.i
recode edu (2/4=1 "college")(0 1=0 "hs or lower")(else=.), gen(college)	
	
rename INTINTL_? intintl_?
rename INTMIL_? intmil_?

rename *_1 *_2008
rename *_2 *_2010
rename *_3 *_2012

rename income06_2008 income_2008
rename income06_2010 income_2010
rename income06_2012 income_2012

gen id = _n + 3000

save ".\2008\GSS_panel_2008_short.dta", replace


*2010-2014
use ".\2010\GSS_panel2010w123_R6 - stata13.dta", clear

keep  age_1 age_2 age_3 confed_1 confed_2 confed_3 coninc_1 coninc_2 coninc_3 conjudge_1 conjudge_2 conjudge_3 conlegis_1 conlegis_2 conlegis_3 ///
	degree_1 degree_2 degree_3 educ_1 educ_2 educ_3 govdook_1 govdook_2 govdook_3 ///
	hompop_1 hompop_2 hompop_3 id_1 id_2 id_3 income06_1 income06_2 income06_3 ///
	INTINTL_1 INTINTL_2 INTINTL_3 INTMIL_1 INTMIL_2 INTMIL_3 INTLPOL_1 INTLPOL_2 INTLPOL_3 LOCVOTE_1 LOCVOTE_2 locvote_3 ///
	madeg_1 madeg_2 madeg_3 maeduc_1 maeduc_2 maeduc_3 masei_1 masei_2 masei_3 ///
	padeg_1 padeg_2 padeg_3 paeduc_1 paeduc_2 paeduc_3 pasei_1 pasei_2 pasei_3 partyid_1 partyid_2 partyid_3  ///
	polviews_1 polviews_2 polviews_3 race_1 race_2 race_3 satfin_1 satfin_2 satfin_3 ///
	sei_1 sei_2 sei_3 sex_1 sex_2 sex_3 wrkstat_1 wrkstat_2 wrkstat_3 born_1

clonevar sex = sex_1	
clonevar race = race_1
recode race (2=1 "black")(1 3=0 "other")(else=.), gen(black)
recode race (3=1 "other race")(1 2=0 "white or black")(else=.), gen(race_other)

recode born_1 (1=0 "no migrant")(2=1 "migrant")(else=.), gen(migrant)

gen birthyear = 2010 - age_1
drop age_*
	
gen edu = degree_3
replace edu = degree_2 if edu==.a | edu==.i
replace edu = degree_1 if edu==.a | edu==.i
recode edu (2/4=1 "college")(0 1=0 "hs or lower")(else=.), gen(college)

rename INTINTL_? intintl_?
rename INTMIL_? intmil_?
rename INTLPOL_? intlpol_?
rename LOCVOTE_? locvote_?

rename *_1 *_2010
rename *_2 *_2012
rename *_3 *_2014

rename income06_2010 income_2010
rename income06_2012 income_2012
rename income06_2014 income_2014

gen id = _n + 6000


save ".\2010\GSS_panel_2010_short.dta", replace




	
**********************
*** Combine waves ****
**********************

*First step: create a wide data set 
use ".\2006\GSS_panel_2006_short.dta", clear

merge 1:1 id using ".\2008\GSS_panel_2008_short.dta", gen(merge0608) 
merge 1:1 id using ".\2010\GSS_panel_2010_short.dta", gen(merge060810) 

drop merge* id_* sex_* race_2*

reshape long confed_ coninc_ conjudge_ conlegis_ degree_ educ_ hompop_ income_ intlpol_ intintl_ intmil_ ///
		madeg_ maeduc_ masei_ padeg_ paeduc_ partyid_ pasei_ polbstgw_ polint1_ polviews_ ///
		satfin_ sei_ wrkstat_ govdook_ locvote_ , ///
		i(id) j(year) 

rename *_ *



**********************
*** Recode data ******
**********************

lab var id "Identifier"
lab var year "Year"


* Household-level data
clonevar hhsize = hompop
clonevar hhinc = coninc
recode satfin (1 2 = 1 "satisfied")(3=0 "not at all satisfied")(else=.), gen(sat_fin)
lab var hhsize "Number of persons in HH"
lab var sat_fin "Satisfaction with financial situation"

gen hhinc_pp = hhinc/hhsize
gen hhinc_pp_sqrt = hhinc/(sqrt(hhsize))

xtile hhinc_dec = hhinc, nq(10) 
xtile hhinc_dec_pp = hhinc_pp, nq(10) 
xtile hhinc_dec_pp_sqrt = hhinc_pp_sqrt, nq(10) 


gen hhinc_dec10 = (hhinc_dec-1)*(10/9)
gen hhinc_dec_pp10 = (hhinc_dec_pp-1)*(10/9)
gen hhinc_dec_pp_sqrt10 = (hhinc_dec_pp_sqrt-1)*(10/9)


*** Individual level

* political issues
fre confed conjudge conlegis govdook intintl intlpol intmil

recode confed (1=1 "interested")(2 3=0 "not interested")(else=.), gen(conf_exec2)
recode conjudge (1=1 "interested")(2 3=0  "not interested")(else=.), gen(conf_ussc2)
recode conlegis (1=1 "interested")(2 3=0  "not interested")(else=.), gen(conf_congress2)
recode intintl (1=1 "interested")(2 3=0  "not interested")(else=.), gen(int_intl2)
recode intmil (1=1 "interested")(2 3=0  "not interested")(else=.), gen(int_mil2)

recode confed (1 2=1 "interested")(3=0 "not interested")(else=.), gen(conf_exec)
recode conjudge (1 2=1 "interested")(3=0  "not interested")(else=.), gen(conf_ussc)
recode conlegis (1 2=1 "interested")(3=0  "not interested")(else=.), gen(conf_congress)
recode intintl (1 2=1 "interested")(3=0  "not interested")(else=.), gen(int_intl)
recode intmil (1 2=1 "interested")(3=0  "not interested")(else=.), gen(int_mil)


*Socio-demographics
recode wrkstat (3 4=1 "unemployed")(1 2 5/8=0 "other")(else=.), gen(unemployed)
recode wrkstat (5/8=1 "nlf")(1/4=0 "other")(else=.), gen(nlf)

fre birthyear
gen age = year-birthyear
gen age18 = age-18
recode age (13/35=1)(36/120=0)(else=.), gen(age1835)

gen female = sex-1




*** save data 
save "gss_long.dta", replace














